// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.core.collision;

import java.util.ArrayList;
import zombie.iso.Vector2;

public final class Polygon {
    public ArrayList<Vector2> points = new ArrayList(4);
    public ArrayList<Vector2> edges = new ArrayList(4);
    float x = 0.0F;
    float y = 0.0F;
    float x2 = 0.0F;
    float y2 = 0.0F;
    Vector2[] vecs = new Vector2[4];
    Vector2[] eds = new Vector2[4];
    static Vector2 temp = new Vector2();

    public void Set(float _x, float _y, float _x2, float _y2) {
        this.x = _x;
        this.y = _y;
        this.x2 = _x2;
        this.y2 = _y2;
        this.points.clear();
        if (this.vecs[0] == null) {
            for (int _int = 0; _int < 4; _int++) {
                this.vecs[_int] = new Vector2();
                this.eds[_int] = new Vector2();
            }
        }

        this.vecs[0].x = _x;
        this.vecs[0].y = _y;
        this.vecs[1].x = _x2;
        this.vecs[1].y = _y;
        this.vecs[2].x = _x2;
        this.vecs[2].y = _y2;
        this.vecs[3].x = _x;
        this.vecs[3].y = _y2;
        this.points.add(this.vecs[0]);
        this.points.add(this.vecs[1]);
        this.points.add(this.vecs[2]);
        this.points.add(this.vecs[3]);
        this.BuildEdges();
    }

    public Vector2 Center() {
        temp.x = this.x + (this.x2 - this.x) / 2.0F;
        temp.y = this.y + (this.y2 - this.y) / 2.0F;
        return temp;
    }

    public void BuildEdges() {
        this.edges.clear();

        for (int _int = 0; _int < this.points.size(); _int++) {
            Vector2 vector20 = (Vector2)this.points.get(_int);
            Vector2 vector21;
            if (_int + 1 >= this.points.size()) {
                vector21 = (Vector2)this.points.get(0);
            } else {
                vector21 = (Vector2)this.points.get(_int + 1);
            }

            this.eds[_int].x = vector21.x - vector20.x;
            this.eds[_int].y = vector21.y - vector20.y;
            this.edges.add(this.eds[_int]);
        }
    }

    public void Offset(float _x, float _y) {
        for (int _int = 0; _int < this.points.size(); _int++) {
            Vector2 vector2 = (Vector2)this.points.get(_int);
            vector2.x += _x;
            vector2.y += _y;
        }
    }

    public void Offset(Vector2 v) {
        this.Offset(v.x, v.y);
    }
}
